---
title: "North Korea - Japanese"
author: "`r Sys.info()['user']`"
date: "`r format(Sys.time(), '%Y-%m-%d')`"
output: html_document
---

# Compare Asahi and Yomiuri sources

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, fig.width = 10, fig.height = 5)
source("functions.R")
dat <- cbind(readRDS("data_lss_ja.RDS"), readRDS("data_newsmap_ja.RDS"))
dat <- subset(dat, class %in% c("kp", "jp"))
events <- yaml::read_yaml("events.yml")
```

```{r}
plot_volume(dat, "asahi", col = color[2], ylim = c(0, 25))
plot_volume(dat, "yomiuri", col = color[1], add = TRUE)
add_events(c(events$JP$military, events$JP$diplomacy), margin = 0.15)
legend("topleft", c("Asahi", "Yomiuri"), 
       col = color[2:1], lty = 1, lwd = 2, horiz = TRUE)
```
```{r}
tb <- table(dat$date, dat$publication)
cor(tb)
```

```{r}
par(mar = c(2.1, 4.1, 1.1, 1.1))
i <- sample(nrow(dat), 10000)
plot(dat$date[i], dat$lss[i], col = rgb(0, 0, 0, 0.1), 
     pch = 16, ylim = c(-2, 2), ylab = "Threat emphasis",
     xlim = as.Date(c("2009-01-01", "2018-12-31")))
abline(h = 0)
add_events(c(events$JP$military, events$JP$diplomacy))
```

```{r}
plot_loess(dat, dat$publication == "asahi", span = 0.1, col = color[2], 
           ylab = "Threat emphasis")
plot_loess(dat, dat$publication == "yomiuri", span = 0.1, col = color[1], add = TRUE)
abline(h = 0)
add_events(c(events$JP$diplomacy, events$JP$military))
legend("bottomleft", c("Asahi", "Yomiuri"), 
       col = color[2:1], lty = 1, lwd = 2, horiz = TRUE)
```

```{r}
plot_loess(dat, dat$class == "jp", span = 0.1, col = color[3],
           ylab = "Threat emphasis")
plot_loess(dat, dat$class == "kp", span = 0.1, col = color[4], add = TRUE)
abline(h = 0)
add_events(c(events$JP$legislation, events$JP$election))
legend("bottomleft", c("Japan", "North Korea"), 
       col = color[3:4], lty = 1, lwd = 2, horiz = TRUE)
```
